// TOWN SCRIPT
//    Town 3: Under Hatherond

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

short i,j,k,r1,choice;

body;

beginstate INIT_STATE;
	enable_add_chars(1);
	set_name(34,"Shaw");
	
// This state called whenever this town is entered.
break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// This state is called every turn the party is in this town.
break;

beginstate 10;
	if (get_flag(3,0) == 1)
		end();
	set_state_continue(11);
break;

beginstate 11;
	print_str("Blocked: West.");
	block_entry(1);
break;

beginstate 12;
	if (get_flag(3,1) == 250)
		end();
	message_dialog("To the south there is a tangible heat, coupled with a faint hissing noise. Strewn about are the remnants of a building, much of which are now covered with cobwebs.","");
	set_flag(3,1,250);
break;

beginstate 14;
	reset_dialog();
	add_dialog_str(0,"On the south wall of this hidden niche is drawn a strange rune. Instead of being engraved, as most runes are, this one is embossed, protruding a quarter-inch outward.",0);
	add_dialog_str(1,"You know enough of Arcane Lore to tell that this is probably a glyph of passing - that is, one which gives you passage to some place. The typical procedure is to touch your palm to the rune briefly.",0);
	add_dialog_str(2,"Do you?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Touch.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(20);
break;

beginstate 15;
	if (get_flag(3,0) == 1)
	end();
	if (get_skill_total(13) >= 4)
		set_state_continue(14);
	set_state_continue(16);
break;

beginstate 16;
	reset_dialog();
	add_dialog_str(0,"On the south wall of this hidden niche is drawn a strange rune. Instead of being engraved, as most runes are, this one is embossed, protruding a quarter-inch outward.",0);
	add_dialog_str(1,"It's probably magical, but you haven't studied enough in Arcane Lore to be able to tell what it's supposed to do, or even how to activate it.",0);
	add_dialog_str(2,"You could bash it with your weapons to try to destroy it. On the other hand, you could try touching it, though dealing with magic that you don't understand is very dangerous.",0);
	add_dialog_str(3,"What do you do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Destroy.");
	add_dialog_choice(2,"Touch.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(17);
	if (choice == 3)
		end();
break;

beginstate 17;
	message_dialog("You take out your weapons and start hacking on the rune. It occurs to you that bashing rock with metal is rather futile, but without any other choice, you keep smiting.",
	  "Suddenly, as yet another blow lands, the rune glows briefly, and you feel a brief tingling sensation. Then the rune fades into the smooth rock surface.");
	set_terrain(39,44,0);		  
	set_flag(3,0,1);
	set_state_continue(18);
break;

beginstate 18;
	message_dialog("You feel a sudden sapping of power.","");
	i = 0;
	while (i < 6) {
		change_char_energy(i,-50);
		i = i + 1;
		}
break;

beginstate 20;
	message_dialog("The rune glows briefly, and you feel a tingling sensation. Then the rune fades into the smooth rock surface.","");
	set_terrain(39,44,0);	
	set_flag(3,0,1);
break;

beginstate 22;
	if (get_flag(3,3) == 250)
		end();
	set_flag(3,3,250);
	message_dialog("It seems that you are not alone in this building. Several armed soldiers stand guard on the south end of this room. They are immediately alerted by your blunt entry.",
	  "One of them runs through the south door, shouting an alarm. The two remaining soldiers draw their weapons and prepare to engage you.");
	activate_hidden_group(1);
break;

beginstate 23;
	if (get_flag(3,4) == 250)
		end();
	reset_dialog();
	add_dialog_str(0,"As you charge through the entryway, the southwest door of the room opens. There, flanked by two guards, is Aeschere himself. He stares at you curiously.",0);
	add_dialog_str(1,"Finally, he speaks. _Pitiful wyrmlings, ever meddling in affairs that are beyond their control. Brave, but foolish. All other accomplices have been apprehended already, with my assurances._",0);
	add_dialog_str(2,"He turns to the soldiers around him. _Capture these with the utmost speed, and lock them in the prison. They shall be questioned later._",0);
	add_dialog_str(3,"With a half-bow, Aeschere exits. The guards stay, ready for combat.",0);
	add_dialog_choice(0,"OK.");
	choice = run_dialog(1);
	set_flag(3,4,250);
	activate_hidden_group(2);
break;

beginstate 25;
	if (get_flag(3,5) == 250)
		end();
	message_dialog("No one ever told you about such an elaborate underground construction beneath Hatherond. Must be a byproduct of immense economic success. Hallways continue to stretch and turn in front of you.","If what Aeschere said was true, then your fellow agents are locked up in the prison already, wherever that is.");
	set_flag(3,5,250);
break;

beginstate 26;
	message_dialog("Apparently, these are records of former and current prisoners. A quick scan reveals that all this bureaucracy is far beyond your comprehension.","");
break;

beginstate 27;
	if (get_flag(3,6) == 250)
		end();
	set_flag(3,6,250);
	message_dialog("A steel key is hanging from the wall here. You take it.",
	  "[You have acquired a Special Item.]");
	change_spec_item(1,1);
break;

beginstate 28;
	if (has_special_item(1) > 0)
		set_state_continue(29);
	set_state_continue(32);
break;

beginstate 29;
	if (get_terrain(9,32) == 12)
		set_state_continue(30);
break;

beginstate 30;
	message_dialog("The door is kept closed by a small steel lock. One of your keys matches the lockhole. You insert and turn it, and are met by a satisfying click.",
	"");
	set_terrain(9,32,16);
	play_sound(9);
break;

beginstate 32;
	if (get_terrain(9,32) == 12)
		set_state_continue(33);
break;

beginstate 33;
	message_dialog("The door is kept closed by a small steel lock. None of your keys fit, and you doubt that any amount of trickery is going to open it for you.","");
break;

beginstate 34;
	if (get_terrain(5,17) == 10)
		set_state_continue(35);
break;

beginstate 35;
	if (character_in_party(328) > 3)
		set_state_continue(37);
	set_state_continue(36);
break;

beginstate 36;
	message_dialog("The door before you is securely locked. A quick check reveals that none of your keys match.","");
break;

beginstate 37;
	message_dialog("The door before you is securely locked. A quick check reveals that none of your keys match. Before you give up, however, Shaw walks up to the door and examines it briefly.","Removing something from his outfit, he works the lock for a few seconds. With a whirl and a click, the door is unlocked.");
	set_terrain(5,17,14);
break;

beginstate 38;
	set_flag(3,9,1);
	reset_dialog();
	add_dialog_str(0,"He spreads his hands. _I have no weapon, and but I will, where I can, help.",0);
	add_dialog_str(1,"[An NPC has joined your party.]",0);
	add_dialog_str(2,"_Then good._ A brief pause. _The stairs climb at northwest. We should go there._",0);	
	choice = run_dialog(1);
break;


beginstate 41;
	if (get_flag(3,7) == 250)
		end();
	set_flag(3,7,250);
	message_dialog("A stairway is in the southeast corner of the room. Before it stands Aeschere with something glittering in his hands. As you enter, he shatters it against the floor. Demonic creatures materialize in the resulting smoke.",
	  "_Brave, but still foolish. I trust that you know where you are headed?_ Aeschere turns up the stairs. The demons attack.");
	activate_hidden_group(3);
break;

beginstate 42;
	reset_dialog();
	add_dialog_str(0,"A stairway leads up. You can hear rapid footsteps coming your direction from the outside. Do you ascend?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Climb.");
	choice = run_dialog(1);
	if (choice == 2)
		set_state_continue(43);
break;

beginstate 43;
	block_entry(1);
	reset_dialog();
	add_dialog_str(0,"As you climb up, there is a rumbling below, and then all light from the room underneath is blocked out. The guards must have placed a barrier down there, probably made of rock, and most likely very difficult to deal with.",0);
	add_dialog_str(1,"In any case, you can't go back down.",0);
	choice = run_dialog(0);
		move_to_new_town(4,24,25);
break;

beginstate 44;
	if (character_in_party(328) > 3)
		set_state_continue(45);
break;

beginstate 45;
	if (get_flag(3,8) == 250)
		end();
	message_dialog("_The stairway climbs should from here a traveling northwest,_ says Shaw.","");
	set_flag(3,8,250);
break;

beginstate 47;
	put_boom_on_space(22,4,1,1);
	put_boom_on_space(22,4,1,1);
	put_boom_on_space(22,4,1,1);
	put_boom_on_space(22,4,1,1);
	put_boom_on_space(22,4,1,1);
	run_animation();
	set_state_continue(48);
break;

beginstate 48;
	message_dialog("The altar crumbles under your blast. Amid the rubble, you find a small, wicked knife. It feels bitterly cold to the touch.","");
	set_terrain(22,4,0);        
	put_item_on_spot(22,4,451);
	put_item_on_spot(22,4,109);
	put_item_on_spot(21,4,109);
	put_item_on_spot(23,4,109);
break;

beginstate 50;
	if (get_flag(230,0) == 250)
		end();
	message_dialog("As you enter this hall, you feel an imperceptable chill, as though this area is somehow colder than the rest of the complex.","");
	set_flag(230,0,250);
break;

beginstate 52;
	message_dialog("These seems to have been the stairs from the complex back up to the city. Unfortunately, they've been completely blocked off by heavy stone obstructions.",
	  "There must be another exit.");
	block_entry(1);
break;

beginstate 54;
	message_dialog("You blast the door with a concentrated bolt of magical energy. The door shivers as the flames run up and down, then falls open.","");
	set_terrain(5,17,14);
break;

beginstate 55;
	message_dialog("Rifling through the desk quickly, you find essentially nothing of interest. There are a few scattered orders, but nothing concerning you.","");
break;

beginstate 56;
	print_str("Blocked: West.");
	if (get_terrain(5,17) == 10)
		set_state_continue(57);
break;

beginstate 57;
	print_str("Blocked: West.");
	if (character_in_party(328) < 4)
		set_state_continue(54);
break;

beginstate 58;
	if (character_in_party(328) < 4)
	message_dialog("The door ahead has an aura that feels like it might be evilly enchanted.","");
break;


